package thread;

public class DaemonThread {
    public static void main(String[] args) throws InterruptedException {

        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {

                Thread deamon=new Thread(new Runnable() {
                    @Override
                    public void run() {
                        while (true){
                            try {
                                Thread.sleep(10);
                                System.out.println("我是守护线程");
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }

                        }
                    }
                });
                deamon.setDaemon(true);
                deamon.start();

                for (int i=0;i<10;i++){
                    try {
                        Thread.sleep(10);
                        System.out.println("启动线程运行=》"+i);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                System.out.println("启动线程退出================");
            }
        });
        thread.start();
        Thread.sleep(1000);
        System.out.println("==================主线程退出================");

    }
}
